<template>
	<view>
		<view class="cart-list">
			<view class="cart-box" v-for="(item,index) in cartData" :key="index">
				<!-- 购买 -->
				<view v-if="item.dynamicType == '1'" class="cart-box-is">
					<!-- 1，头部信息 -->
					<view class="top">
						<view class="top-left">
							<!-- 1.1，头像 -->
							<view class="top-left-head">
								<image :src="item.releaseUserHead"></image>
							</view>
							<!-- 1.2，昵称 -->
							<view class="top-left-name">
								<text>{{item.releaseUserName}}</text>
							</view>
						</view>
						<view class="top-right">
							<!-- 1.3，订单状态 -->
							<text v-if="item.state == '2'">待处理</text>
							<text v-if="item.state == '3'">商家已发货</text>
							<text v-if="item.state == '4'">已送达</text>
							<text v-if="item.state == '5'">已签收</text>
							<text v-if="item.state == '10'">已完成</text>
						</view>
					</view>

					<!-- 2，订单信息 -->
					<view class="center">
						<view class="center-left">
							<!-- 2.1，商品图片 -->
							<!-- mode="widthFix" -->
							<image :src="handlerImgs(item.imgs)"></image>
						</view>
						<view class="center-box">
							<!-- 2.2，商品描述 -->
							<view class="detail">
								<text>描述：{{item.detail}}</text>
							</view>
							<!-- 2.3，价格 -->
							<view class="price">
								<text>实付￥：{{item.price}}</text>
							</view>
						</view>
					</view>
					<!-- {{item.state}} -->
					<!-- 3，底部操作按钮 -->
					<view class="bottom">
						<!-- 3.1，删除按钮 -->
						<view @click="removeBtn(item)" class="sc-btn" v-if="item.state == '10' || item.state == '5'">
							<text>删除订单</text>
						</view>
						<!-- 3.2，验签按钮 -->
						<view @click="changeState(item,'5')" class="yq-btn" v-else-if="item.state == '4'">
							<text>签收</text>
						</view>
						<!-- 3.3，取消按钮 -->
						<view @click="cancelBtn(item)" class="qx-btn" v-else>
							<text>取消订单</text>
						</view>
					</view>
				</view>

				<!-- 赚钱 -->
				<view v-else class="cart-box-not">
					<!-- 1，头部信息 -->
					<view class="top">
						<view class="top-left">
							<!-- 1.1，头像 -->
							<view class="top-left-head">
								<image :src="item.releaseUserHead"></image>
							</view>
							<!-- 1.2，昵称 -->
							<view class="top-left-name">
								<text>{{item.releaseUserName}}</text>
							</view>
						</view>
						<view class="top-right">
							<!-- 1.3，订单状态 -->
							<text v-if="item.state == '6'">待处理</text>
							<text v-if="item.state == '7'">处理中</text>
							<text v-if="item.state == '8'">待签收</text>
							<text v-if="item.state == '9'">已签收</text>
							<text v-if="item.state == '10'">已完成</text>
						</view>
					</view>

					<!-- 2，订单信息 -->
					<view class="center">
						<view class="center-left">
							<!-- 2.1，商品图片 -->
							<!-- mode="widthFix" -->
							<image :src="handlerImgs(item.imgs)"></image>
						</view>
						<view class="center-box">
							<!-- 2.2，商品描述 -->
							<view class="detail">
								<text>描述：{{item.detail}}</text>
							</view>
							<!-- 2.3，价格 -->
							<view class="price">
								<text>赏金￥：{{item.price}}</text>
							</view>
						</view>
					</view>

					<!-- 3，底部操作按钮 -->
					<view class="bottom">
						<!-- 3.1，删除按钮 -->
						<view v-if="item.state == '10'">
							<view @click="removeBtn(item)" class="sc-btn">
								<text>删除订单</text>
							</view>
						</view>
						<!-- 3.2，操作按钮 -->
						<view v-else>
							<view class="bottom-cz">
								<view class="cz-btn">
									<view @click="changeState(item,'7')"
										:class="[ parseInt(item.state) >= 7 ? 'cart-active' :'']">开始处理
									</view>
								</view>
								<view class="cz-btn">
									<view @click="changeState(item,'8')"
										:class="[ parseInt(item.state) >= 8 ? 'cart-active' :'']">处理完成</view>
								</view>
								<!-- <view class="cz-btn">
									<view @click="tipsBtn" :class="[ parseInt(item.state) >= 9 ? 'cart-active' :'']">已验签
									</view>
								</view> -->
								<!-- <view class="cz-btn">
									<view :class="[ parseInt(item.state) >= 10 ? 'cart-active' :'']">完成</view>
								</view> -->

								<view class="lq-btn">
									<view @click="drawBtn(item)">领取赏金</view>
								</view>
							</view>
							<view class="bottom-qq">
								<view class="zw-btn"></view>

								<view class="quxiao-btn">
									<view @click="cancelBtnByZq(item)">取消订单</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: ['cartData'],
		data() {
			return {
				defaultImg: require('@/static/img/common/null_address.svg')
			}
		},
		methods: {
			//1，图片处理
			handlerImgs(imgs) {
				if (imgs == null || imgs == '') {
					return this.defaultImg
				} else {
					const img = imgs.split(',')
					return img[0]
				}
			},
			//2，删除订单
			async cancelBtn(item) {
				var that = this
				uni.$isShowModal('是否取消订单？').then(resultState => {
					if (resultState) {
						that.$emit('cancelBtn', item)
					}
				})
			},
			async cancelBtnByZq(item) {
				var that = this
				uni.$isShowModal('是否取消订单？').then(resultState => {
					if (resultState) {
						that.$emit('cancelBtnByZq', item)
					}
				})
			},
			//4，删除订单
			async removeBtn(item) {
				var that = this
				uni.$isShowModal('是否删除订单？删除后无法恢复！').then(resultState => {
					if (resultState) {
						that.$emit('removeBtn', item)
					}
				})
			},
			//5，改变订单状态
			async changeState(item, state) {
				var msg = ''
				if (state == '7') {
					msg = '是否已开始处理订单？'
				} else if (state == '8') {
					msg = '是否已经处理完成订单？'
				} else if (state == '5') {
					msg = '是否确认签收?'
				}
				
				var that = this
				uni.$isShowModal(msg).then(resultState => {
					if (resultState) {
						that.$emit('changeState', item, state)
					}
				})
			},
			//6，提醒
			async tipsBtn() {
				var that = this
				uni.$isShowModal('等待商家验签！').then(resultState => {
					if (resultState) {
						that.$emit('changeState', item, state)
					}
				})
				
			},
			//7，领取现金
			async drawBtn(item) {
				if (item.state != '9') {
					return uni.$showMsg('等商家验签后才能领取现金！');
				}
				this.$emit('drawBtn', item)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cart-box {
		background: #fff;
		width: 90%;
		margin-left: 2%;
		padding: 3%;
		border-radius: 20rpx;
		margin-top: 30rpx;

		.top {
			display: flex;
			justify-content: space-between;
			height: 60rpx;

			.top-left {
				display: flex;

				.top-left-head {
					image {
						margin-top: 5rpx;
						width: 50rpx;
						height: 50rpx;
						border-radius: 50%;
					}
				}

				.top-left-name {
					line-height: 60rpx;

					text {
						margin-left: 10rpx;
						font-size: 32rpx;
					}
				}

			}

			.top-right {
				line-height: 60rpx;
				font-size: 32rpx;
			}
		}

		.center {
			display: flex;
			border-bottom: 1rpx solid #eee;

			.center-left {
				width: 30%;

				image {
					margin: 20rpx 0;
					width: 90%;
					height: 200rpx;
					border-radius: 20rpx;
				}
			}

			.center-box {
				margin-top: 20rpx;
				width: 70%;

				.detail {
					height: 100rpx;

					text {
						display: -webkit-box;
						/** 对象作为伸缩盒子模型显示 **/
						overflow: hidden;
						word-break: break-all;
						/* break-all(允许在单词内换行。) https://www.w3school.com.cn/cssref/pr_word-break.asp*/
						text-overflow: ellipsis;
						/* 超出部分省略号 */
						-webkit-box-orient: vertical;
						/** 设置或检索伸缩盒对象的子元素的排列方式 **/
						-webkit-line-clamp: 2;
						/** 显示的行数 **/
					}
				}

				.price {
					height: 100rpx;
					line-height: 150rpx;
					text-align: right;
				}
			}
		}

		.bottom {
			width: 100%;
			position: relative;
			height: 80rpx;
			//padding: 10rpx 0;

			.sc-btn {
				// position: absolute;
				//right: 0;
				// top: 10rpx;
				height: 60rpx;
				width: 24%;
				margin-left: 76%;
				text-align: center;
				line-height: 60rpx;
				border: 1rpx solid red;
				border-radius: 30rpx;

				text {
					font-size: 28rpx;
					color: red;
				}
			}

			.yq-btn {
				position: absolute;
				right: 0;
				top: 10rpx;
				height: 60rpx;
				width: 150rpx;
				text-align: center;
				line-height: 60rpx;
				border: 1rpx solid #26C55E;
				border-radius: 30rpx;

				text {
					font-size: 28rpx;
					color: #26C55E;
				}
			}

			.qx-btn {
				position: absolute;
				right: 0;
				top: 10rpx;
				height: 60rpx;
				width: 150rpx;
				text-align: center;
				line-height: 60rpx;
				border: 1rpx solid #C85611;
				border-radius: 30rpx;

				text {
					font-size: 28rpx;
					color: #C85611;
				}
			}
		}


		.cart-box-is {
			.top-right {
				text {
					color: #C96730;
				}
			}

			.price {
				text {
					color: #C96730;
				}
			}

		}

		.cart-box-not {
			.top-right {
				text {
					color: #81C7D5;
				}
			}

			.price {
				text {
					color: #81C7D5;
				}
			}

			.bottom-cz {
				display: flex;

				.cz-btn {
					width: 25%;
					//position: relative;

					view {
						//position: absolute;
						//right: 0;
						width: 80%;
						margin-left: 20%;
						height: 60rpx;
						border: 1rpx solid #81C7D5;
						border-radius: 30rpx;
						line-height: 60rpx;
						text-align: center;
						font-size: 25rpx;
						//color: #81C7D5;
					}
				}

				.lq-btn {
					width: 25%;

					view {
						//position: absolute;
						//right: 0;
						width: 80%;
						margin-left: 20%;
						height: 60rpx;
						border: 1rpx solid #26C55E;
						border-radius: 30rpx;
						line-height: 60rpx;
						text-align: center;
						font-size: 25rpx;
						color: #26C55E;
					}
				}

			}

			.bottom-qq {
				display: flex;
				margin-top: 20rpx;

				.zw-btn {
					width: 75%;
				}

				.quxiao-btn {
					width: 25%;

					view {
						//position: absolute;
						//right: 0;
						width: 80%;
						margin-left: 20%;
						height: 60rpx;
						border: 1rpx solid red;
						border-radius: 30rpx;
						line-height: 60rpx;
						text-align: center;
						font-size: 25rpx;
						color: red;
					}
				}
			}

		}

	}


	.cart-active {
		background-color: #81C7D5;
		color: #fff;
	}
</style>